package com.qf.blog.controller;

import com.qf.blog.entity.User;
import com.qf.blog.exception.BlogException;
import com.qf.blog.service.impl.FollowerService;
import com.qf.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/follower")
public class FollowerController {

    @Autowired
    private FollowerService followerService;

    @GetMapping("/user/{followerUserId}")
    public Result followerUser(@PathVariable Integer followerUserId, HttpSession session) {

        // 1.判断用户是否登录
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser == null) {
            throw new BlogException(1002, "请先登录");
        }

        // 2.使用当前用户去关注followerUserId
        followerService.followerUser(loginUser.getId(), followerUserId);

        return Result.ok();
    }
}
